package com.baixun.gassystem.service.impl;

import com.baixun.gasentity.entity.DataEntity;
import com.baixun.gasentity.entity.UserUrl;
import com.baixun.gassystem.mapper.DataMapper;
import com.baixun.gassystem.mapper.UserUrlMapper;
import com.baixun.gassystem.service.DataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: 上海燃气驾驶舱
 * @description: 前端传入测试数据
 * @author: yesong
 **/
@Service
public class DataServiceImpl extends ServiceImpl<DataMapper, DataEntity> implements DataService {

    @Autowired
    private UserUrlMapper userUrlMapper;

    @Override
    public boolean uploadData(String frontEndData, String jsonData) {
        DataEntity dataEntity = new DataEntity();
        dataEntity.setFrontEndData(frontEndData);
        dataEntity.setData(jsonData);

        // 使用 MyBatis Plus 提供的 save 方法
        return this.save(dataEntity);
    }

    @Override
    public boolean updateData(Long id, String frontEndData, String jsonData) {
        DataEntity dataEntity = this.getById(id);
        if (dataEntity != null) {
            dataEntity.setFrontEndData(frontEndData);
            dataEntity.setData(jsonData);

            // 使用 MyBatis Plus 提供的 updateById 方法
            return this.updateById(dataEntity);
        }
        return false;
    }

    @Override
    public String getData( UserUrl url) {
        return userUrlMapper.getUrl(url);
    }
}
